/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.manage.service;

import cn.hutool.core.bean.BeanUtil;
import info.peigen.hotpot.business.customer.core.repository.entity.CustomerTechEntity;
import info.peigen.hotpot.business.customer.manage.convertor.CustomerTechManageConvertor;
import info.peigen.hotpot.business.customer.manage.form.CustomerTechManageCreateForm;
import info.peigen.hotpot.business.customer.manage.form.CustomerTechManageEditForm;
import info.peigen.hotpot.business.customer.manage.form.CustomerTechManageSearchForm;
import info.peigen.hotpot.business.customer.manage.info.CustomerTechManageInfo;
import info.peigen.hotpot.business.customer.manage.repository.service.CustomerTechManageRepository;
import info.peigen.hotpot.common.core.result.PageResult;
import org.beetl.sql.core.query.LambdaQuery;
import org.beetl.sql.core.query.Query;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * <b>(CustomerTechManageService)</b>
 * 管理后台 "客户模块与技术相关的内容" 服务
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023-09-09
 */
@SuppressWarnings("unused")
@Component
public class CustomerTechManageService {
    @Inject
    CustomerTechManageRepository customerTechManageRepository;

    public PageResult<CustomerTechManageInfo> page(CustomerTechManageSearchForm form) {
        LambdaQuery<CustomerTechEntity> lambdaQuery = customerTechManageRepository.getMapper().createLambdaQuery()
                .andLike(CustomerTechEntity::getCustomerId, Query.filterLikeEmpty(form.getCustomerId(), false, true))
                .andLike(CustomerTechEntity::getPartnerId, Query.filterLikeEmpty(form.getPartnerId(), false, true));

        return customerTechManageRepository.page(form.getPageNum(), form.getPageSize(), lambdaQuery, CustomerTechManageConvertor::convertToInfo);
    }

    public void create(CustomerTechManageCreateForm form) {
        CustomerTechEntity entity = BeanUtil.copyProperties(form, CustomerTechEntity.class);
        customerTechManageRepository.save(entity);
    }

    public void edit(CustomerTechManageEditForm form) {
        CustomerTechEntity entity = BeanUtil.copyProperties(form, CustomerTechEntity.class);
        customerTechManageRepository.saveOrUpdate(entity);
    }

    public void remove(Integer id) {
        customerTechManageRepository.delete(id);
    }
}